﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CollegeSim.CourseScheduler.Domain.Entities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CollegeSim.CourseScheduler.Domain.Test
{
    [TestClass]
    public class StudentTest
    {
        #region [ Property Tests ]

        // Id

        [TestMethod]
        public void IdDefaultValueTest()
        {
            var student = new Student();

            Assert.AreEqual(0, student.Id);
        }

        // FirstName

        [TestMethod]
        public void FirstNameEmptyTest()
        {
            var assert = false;

            try
            {
                var student = new Student
                {
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    YearsAttended = 2,
                    GPA = 3.755m
                };

                student.FirstName = "";
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void FirstNameNullTest()
        {
            var assert = false;

            try
            {
                var student = new Student
                {
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    YearsAttended = 2,
                    GPA = 3.755m
                };

                student.FirstName = null;
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void FirstNameExcessLengthTest()
        {
            var assert = false;

            try
            {
                var student = new Student
                {
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    YearsAttended = 2,
                    GPA = 3.755m
                };

                student.FirstName = "FirstName FirstName FirstName";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        // LastName

        [TestMethod]
        public void LastNameEmptyTest()
        {
            var assert = false;

            try
            {
                var student = new Student
                {
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    YearsAttended = 2,
                    GPA = 3.755m
                };

                student.LastName = "";
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void LastNameNullTest()
        {
            var assert = false;

            try
            {
                var student = new Student
                {
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    YearsAttended = 2,
                    GPA = 3.755m
                };

                student.LastName = null;
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void LastNameExcessLengthTest()
        {
            var assert = false;

            try
            {
                var student = new Student
                {
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    YearsAttended = 2,
                    GPA = 3.755m
                };

                student.LastName = "LastName LastName LastName LastName";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        // PhoneNumber

        [TestMethod]
        public void PhoneNumberExcessLengthTest()
        {
            var assert = false;

            try
            {
                var student = new Student
                {
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    YearsAttended = 2,
                    GPA = 3.755m
                };

                student.PhoneNumber = "PhoneNumber PhoneNumber";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        // Email

        [TestMethod]
        public void EmailExcessLengthTest()
        {
            var assert = false;

            try
            {
                var student = new Student
                {
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    YearsAttended = 2,
                    GPA = 3.755m
                };

                student.Email = "Email Email Email Email Email Email Email Email Email Email";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        // YearsAttended

        [TestMethod]
        public void YearsAttendedBelowRangeTest()
        {
            var assert = false;

            try
            {
                var student = new Student
                {
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    YearsAttended = 2,
                    GPA = 3.755m
                };

                student.YearsAttended = -1;
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void YearsAttendedAboveRangeTest()
        {
            var assert = false;

            try
            {
                var student = new Student
                {
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    YearsAttended = 2,
                    GPA = 3.755m
                };

                student.YearsAttended = 5;
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        // GPA

        [TestMethod]
        public void GPABelowRangeTest()
        {
            var assert = false;

            try
            {
                var student = new Student
                {
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    YearsAttended = 2,
                    GPA = 3.755m
                };

                student.GPA = -1;
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void GPAAboveRangeTest()
        {
            var assert = false;

            try
            {
                var student = new Student
                {
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    YearsAttended = 2,
                    GPA = 3.755m
                };

                student.GPA = 5;
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        #endregion

        #region [ Method Tests ]

        [TestMethod]
        public void ToStringTest()
        {
            var student = new Student
            {
                FirstName = "Ryan",
                LastName = "Redburn",
                PhoneNumber = "123-456-7890",
                Email = "rredburn@email.com",
                YearsAttended = 2,
                GPA = 3.755m
            };
   
            Assert.AreEqual(student.LastName + ", " + student.FirstName + " - " + student.PhoneNumber, student.ToString());
        }

        #endregion
    }
}
